package net.minecraft.src;

import java.util.*;

public class BlockPixel extends Block
{
	public  static  int activeInactiveMask =  1;//0001
	public  static  int colorMask = 14;//1110 


    public int getRenderBlockPass()
    {
        return 0;
    }

    protected BlockPixel(int i)
    {
        super(i,Material.glass);

    }
    
    protected int damageDropped(int i) {
        return i & colorMask;
    }

	
    public int getBlockTextureFromSideAndMetadata(int i, int j) {

		if( getState( j )== mod_Pixel.pixelInactiveId  )
		{
			switch( getColor(j) )
			{
				case  mod_Pixel.pixelRedId:
					return mod_Pixel.texturePixelInactiveRedId;
				case  mod_Pixel.pixelBlueId:
					return mod_Pixel.texturePixelInactiveBlueId;					
				case  mod_Pixel.pixelGreenId:
					return mod_Pixel.texturePixelInactiveGreenId;
				case  mod_Pixel.pixelYellowId:
					return mod_Pixel.texturePixelInactiveYellowId;

			}
		}
		else
		{
			switch( getColor(j) )
			{
				case  mod_Pixel.pixelRedId:
					return mod_Pixel.texturePixelRedId;
				case  mod_Pixel.pixelBlueId:
					return mod_Pixel.texturePixelBlueId;					
				case  mod_Pixel.pixelGreenId:
					return mod_Pixel.texturePixelGreenId;
				case  mod_Pixel.pixelYellowId:
					return mod_Pixel.texturePixelYellowId;

			}
		}
    
		return -1;
    }
    
    

    public void  setState( World world, int i, int j, int k,  int active )
    {
		int  meta = world.getBlockMetadata(i,j,k);
		world.setBlockMetadataWithNotify( i,j,k,(meta & colorMask) + active );
    }
    public int  getState( int metadata )
    {
			return  metadata & activeInactiveMask; 
    }
    public int getColor( int metadata )
    {
		return metadata & colorMask;
    }
    
    public boolean isOpaqueCube()
    {
        return false;
    }

    public int tickRate()
    {
        return 2;
    }

    public float getBlockBrightness(IBlockAccess par1IBlockAccess, int par2, int par3, int par4)
    {
    	if(mod_Pixel.pixelActiveId   == getState( par1IBlockAccess.getBlockMetadata(par2, par3, par4) ))
    		return par1IBlockAccess.getBrightness(par2, par3, par4, 15);
    	else
    		return par1IBlockAccess.getBrightness(par2, par3, par4, 0);
    }
    /**
     * 'Goes straight to getLightBrightnessForSkyBlocks for Blocks, does some fancy computing for Fluids'
     */
    public int getMixedBrightnessForBlock(IBlockAccess par1IBlockAccess, int par2, int par3, int par4)
    {
    	
    	if(mod_Pixel.pixelActiveId  == getState( par1IBlockAccess.getBlockMetadata(par2, par3, par4) ))
    		return par1IBlockAccess.getLightBrightnessForSkyBlocks(par2, par3, par4,  15);
    	else
    		return par1IBlockAccess.getLightBrightnessForSkyBlocks(par2, par3, par4,  0);
    }


    public void onBlockAdded(World world, int i, int j, int k)
    {
        super.onBlockAdded(world, i, j, k);
        world.scheduleBlockUpdate(i, j, k, blockID, tickRate());
    }

    public void onBlockRemoval(World world, int i, int j, int k)
    {
    	super.onBlockRemoval(world, i, j, k);
    }

    public boolean isPoweringTo(IBlockAccess iblockaccess, int i, int j, int k, int l)
    {
    	return false;
    }

    private boolean func_30002_h(World world, int i, int j, int k)
    {
 
        if ( world.isBlockIndirectlyProvidingPowerTo(i, j - 1, k, 0))
        {
            return true;
        }
        if (world.isBlockIndirectlyProvidingPowerTo(i, j, k - 1, 2))
        {
            return true;
        }
        if (world.isBlockIndirectlyProvidingPowerTo(i, j, k + 1, 3))
        {
            return true;
        }
        if (world.isBlockIndirectlyProvidingPowerTo(i - 1, j, k, 4))
        {
            return true;
        }
        return world.isBlockIndirectlyProvidingPowerTo(i + 1, j, k, 5);
    }

    public void updateTick(World world, int i, int j, int k, Random random)
    {
    	
        boolean flag = func_30002_h(world, i, j, k);
        if ( !flag  &&  mod_Pixel.pixelActiveId   == getState( world.getBlockMetadata(i, j, k)) )
        {
        	setState(  world,  i,  j,  k,  mod_Pixel.pixelInactiveId);
        }
        else if (flag && mod_Pixel.pixelActiveId  != getState( world.getBlockMetadata(i, j, k))  )
        {

        	setState(  world,  i,  j,  k,  mod_Pixel.pixelActiveId);
                 
        }
    }


    public void onNeighborBlockChange(World world, int i, int j, int k, int l)
    {
        super.onNeighborBlockChange(world, i, j, k, l);
        world.scheduleBlockUpdate(i, j, k, blockID, tickRate());
    }

    public boolean isIndirectlyPoweringTo(World world, int i, int j, int k, int l)
    {
    	
    	if ( 
    		        world.getBlockId(i, j, k) == mod_Pixel.blockPixel.blockID 
    			&&  blockID == mod_Pixel.blockPixel.blockID 
    			)
    		return  false;
    	else			
    		return  false;

    }

    public int idDropped(int i, Random random, int j)
    {
        return mod_Pixel.blockPixel.blockID;
    }

    public boolean canProvidePower()
    {
        return false;
    }

}
